﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
using HospitalSystem.Core;

namespace HospitalSystem
{
    public partial class showcidinfo : System.Web.UI.Page
    {
        private show_Image _showimage;
        DataClasses1DataContext db = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Pick Value From Valuable @ Server
                String ShowValue = (string)Session["CID"];
                cid_label.Text = ShowValue;
                String ShowValue2 = (string)Session["LastName"];
                lname.Text = ShowValue2;
                String ShowValue3 = (string)Session["FirstName"];
                fname.Text = ShowValue3;

                //Hide Warning Panel
                WarningPanel.Visible = false;

                //Show Picture @aspx
                _showimage = new show_Image();
                _showimage.show_Images(cid_label, Image1);

                //Show Value @ Gridview
                ShowValueAtGridview(ShowValue);

                
            }
        }

        public string GetUrl(object CaseNo)
        {
            Session["CaseNo"] = Server.UrlEncode(CaseNo.ToString());
            string url = "diagnosemedical.aspx";
            return url;
        }

        private void ShowValueAtGridview(string _CID)
        {
            DataTable dtOK = new DataTable();
            dtOK.Columns.Add("CaseNo");
            dtOK.Columns.Add("EvalDateTime");

            DataTable dtNo = new DataTable();
            dtNo.Columns.Add("CaseNo");
            dtNo.Columns.Add("EvalDateTime");

            var queryEvaluation = from a in db.Persons
                                  join b in db.Evaluations on a.CID equals b.CID
                                  where a.CID.Equals(_CID)
                                  select new
                                  {
                                      b.CaseNo,
                                      b.EvalDateTime
                                  };

            foreach (var q in queryEvaluation)
            {
                DateTime _EvalDateTime = Convert.ToDateTime(q.EvalDateTime);
                //Calculate Days
                double totalDaysofEvaluation = (DateTime.Now - _EvalDateTime).TotalDays;
                if (totalDaysofEvaluation < 14.0)
                {
                    //Can Edit Screening Data
                    dtOK.Rows.Add(q.CaseNo,q.EvalDateTime);
                }
                else if (totalDaysofEvaluation > 14.0 || totalDaysofEvaluation == 14.0)
                {
                    //Cannot Edit Screening Data
                    dtNo.Rows.Add(q.CaseNo, q.EvalDateTime);
                }
                else
                {
                    ;
                }
            }
            Casenoshow.DataSource = dtNo;
            Casenoshow.DataBind();
            CaseNoShow2.DataSource = dtOK;
            CaseNoShow2.DataBind();

            //Check Condition For Warning
            if (dtOK.Rows.Count == 0)
            {
                WarningPanel.Visible = true;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/cal.aspx");
        }
    }
}